package initialize

import (
  "github.com/gin-gonic/gin"
  "github.com/swaggo/gin-swagger"
  "github.com/swaggo/gin-swagger/swaggerFiles"
  _ "livefind/docs"
  "livefind/global"
  "livefind/middleware"
  "livefind/router"
  "livefind/utils/logger"
  "net/http"
)

// 初始化总路由

func Routers() *gin.Engine {
  var Router = gin.Default()
  Router.StaticFS(global.GVA_CONFIG.Local.Path, http.Dir(global.GVA_CONFIG.Local.Path)) // 为用户头像和文件提供静态地址
  // Router.Use(middleware.LoadTls())  // 打开就能玩https了
  logger.Info("use middleware logger")
  // 跨域
  Router.Use(middleware.Cors()) // 如需跨域可以打开
  logger.Info("use middleware cors")
  Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
  logger.Info("register swagger handler")
  // 方便统一添加路由组前缀 多服务器上线使用

  //获取路由组实例
  systemRouter := router.RouterGroupApp.System
  exampleRouter := router.RouterGroupApp.Example
  autocodeRouter := router.RouterGroupApp.Autocode
  caseRouter := router.RouterGroupApp.Case
  evidenceRouter := router.RouterGroupApp.Evidence
  PublicGroup := Router.Group("")
  {
    systemRouter.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权
    systemRouter.InitInitRouter(PublicGroup) // 自动初始化相关
  }
  PrivateGroup := Router.Group("/api/v1")
  //PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
  {
    systemRouter.InitApiRouter(PrivateGroup)                    // 注册功能api路由
    systemRouter.InitJwtRouter(PrivateGroup)                    // jwt相关路由
    systemRouter.InitUserRouter(PrivateGroup)                   // 注册用户路由
    systemRouter.InitMenuRouter(PrivateGroup)                   // 注册menu路由
    systemRouter.InitEmailRouter(PrivateGroup)                  // 邮件相关路由
    systemRouter.InitSystemRouter(PrivateGroup)                 // system相关路由
    systemRouter.InitCasbinRouter(PrivateGroup)                 // 权限相关路由
    systemRouter.InitAutoCodeRouter(PrivateGroup)               // 创建自动化代码
    systemRouter.InitAuthorityRouter(PrivateGroup)              // 注册角色路由
    systemRouter.InitSysDictionaryRouter(PrivateGroup)          // 字典管理
    systemRouter.InitSysOperationRecordRouter(PrivateGroup)     // 操作记录
    systemRouter.InitSysDictionaryDetailRouter(PrivateGroup)    // 字典详情管理
    exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由
    exampleRouter.InitExcelRouter(PrivateGroup)                 // 表格导入导出
    exampleRouter.InitSimpleUploaderRouter(PrivateGroup)        // 断点续传（插件版）
    exampleRouter.InitCustomerRouter(PrivateGroup)              // 客户路由

    // Code generated by livefind Begin; DO NOT EDIT.
    autocodeRouter.InitSysAutoCodeExampleRouter(PrivateGroup)
    // Code generated by livefind End; DO NOT EDIT.

    caseRouter.InitCasesRouter(PrivateGroup)
    evidenceRouter.InitEvidencesRouter(PrivateGroup)
  }
  logger.Info("router register success")
  return Router
}
